package com.hengx.cellview.cell;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;

public class DrawableCell extends Cell {

    private Drawable drawable;
    
    @Override
    public void draw(Paint paint, Canvas canvas) {
        if (drawable != null) {
            drawable.draw(canvas);
        }
    }
    
    @Override
    public void setBounds(float x, float y, float endX, float endY) {
        super.setBounds(x, y, endX, endY);
        if (drawable != null) {
            drawable.setBounds(Math.round(x), Math.round(y), Math.round(endX), Math.round(endY));
        }
    }
    

    public Drawable getDrawable() {
        return this.drawable;
    }

    public void setDrawable(Drawable drawable) {
        this.drawable = drawable;
        if (drawable != null) {
            RectF rect = getBounds();
            drawable.setBounds(Math.round(rect.left), Math.round(rect.top), Math.round(rect.right), Math.round(rect.bottom));
        }
    }
}
